package com.wjh.kt_vod.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjh.kt_vod.model.vod.VideoVisitor;
import com.wjh.kt_vod.service.VideoVisitorService;
import com.wjh.kt_vod.mapper.VideoVisitorMapper;
import com.wjh.kt_vod.vo.vod.VideoVisitorCountVo;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;


/**
 *
 */
@Service
public class VideoVisitorServiceImpl extends ServiceImpl<VideoVisitorMapper, VideoVisitor>
    implements VideoVisitorService{

    @Override
    public Map<String, Object> findCount(Long courseId, String startDate, String endDate) {

//        调用mapper的方法
        List<VideoVisitorCountVo> videoVisitorVoList =
                baseMapper.findCount(courseId,startDate,endDate);

        HashMap<String, Object> map = new HashMap<>();

        List<Date> dateList =
                videoVisitorVoList.stream().map(VideoVisitorCountVo::getJoinTime).
                        collect(Collectors.toList());

        List<Integer> countList = videoVisitorVoList.stream().map(VideoVisitorCountVo::getUserCount)
                .collect(Collectors.toList());
//        放到map集合

        //放到map集合
        map.put("xData", dateList);
        map.put("yData", countList);
        return map;
    }
}




